package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.SysHz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsQualityInspectionListDetailed;
import com.jy.wms.service.WmsQualityInspectionListDetailedService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsQualityInspectionListDetailedController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Mon Nov 06 14:48:21 CST 2017
 */
@Controller
@RequestMapping("/wmsqualityinspectionlistdetailed")
@Api(value = "/wmsqualityinspectionlistdetailed", description = "质检单明细")
public class  WmsQualityInspectionListDetailedController extends BaseController<WmsQualityInspectionListDetailedService,WmsQualityInspectionListDetailed> {

    @PostMapping(value = "list/{sszjdid}")
    @ApiOperation(value = "质检单 GET查看单个质检单所有明细",response = JSONObject.class, notes = "GET查看单个质检单所有明细")
    public @ResponseBody
    JSONObject getWmsQualityInspectionListDetailedById(@PathVariable("sszjdid") String sszjdid) {
        JSONObject json =getJSONObject();

        List<WmsQualityInspectionListDetailed> list =  new ArrayList<WmsQualityInspectionListDetailed>();
        try {
            list=baseService.baseSelectMxBySszjdid(sszjdid);
            json = SetStatus.setSearchType(JSONArray.fromObject(list).toString(),(int) list.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
    @PostMapping(value = "/addZljy")
    @ApiOperation(value = "质检单 POST质量检验",response = JSONObject.class, notes = "POST质量检验")
    public @ResponseBody JSONObject addZljy(@RequestBody Map<String,Object> map) {
        try {
            baseService.addZljy(map);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"质量检验成功","","");
        }catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.warning.toString(),"质量检验失败",e.getMessage(),"");
        }catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"质量检验成功","","");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"质量检验失败",e.getMessage(),"");
        }
    }
    @PostMapping(value = "/editZjd")
    @ApiOperation(value = "质检单 POST修改质检单",response = JSONObject.class, notes = "POST修改质检单")
    public @ResponseBody JSONObject addZljy(@RequestBody List<WmsQualityInspectionListDetailed> list) {
        try {
            baseService.baseUpdateByPrimaryKeySelective(list);
           return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"修改质检单成功","","");
        }catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.warning.toString(),"修改质检单失败",e.getMessage(),"");
        }catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"修改质检单成功","","");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"修改质检单失败",e.getMessage(),"");
        }
    }
}
